package com.virtium.vpc.action.controller;

import java.util.ArrayList;
import java.util.Iterator;

import com.virtium.vpc.dao.DAOFactory;
import com.virtium.vpc.dao.VpcModulerankDAO;
import com.virtium.vpc.hibernate.model.VpcModulerank;

public class VpcModulerankManager {
	private static ArrayList<VpcModulerank> arrVpcModulerank = null;

	public static ArrayList<VpcModulerank> getAll() {
		try {
			if (arrVpcModulerank != null && arrVpcModulerank.size() > 0)
				return arrVpcModulerank;
			VpcModulerankDAO VpcModulerankDAO = DAOFactory.getInstance()
					.getVpcModulerankDAO();
			arrVpcModulerank = new ArrayList<VpcModulerank>();
			arrVpcModulerank.addAll(VpcModulerankDAO.findAll());
		} catch (Exception ex) {
		}
		return arrVpcModulerank;
	}
	
	public static String getTextByID(int id){
		getAll();
		Iterator<VpcModulerank> iterObject = arrVpcModulerank.listIterator();
		while(iterObject.hasNext()){
			VpcModulerank object = iterObject.next();
			if(object.getId().equals(id))return object.getText();
			
		}
		return "";
	}
	
	public static void AddNew(String text){
		try{
			VpcModulerank object = new VpcModulerank();
			object.setText(text);
			VpcModulerankDAO ObjectDAO = DAOFactory.getInstance().getVpcModulerankDAO();
			ObjectDAO.save(object);
			arrVpcModulerank = null;
		}catch(Exception ex){
			
		}
	}
	
	public static void Delete(int id){
		try{
			
			VpcModulerankDAO ObjectDAO = DAOFactory.getInstance().getVpcModulerankDAO();
			VpcModulerank object = ObjectDAO.findById(id);
			ObjectDAO.delete(object);
			arrVpcModulerank = null;
		}catch(Exception ex){
			
		}
	}
}
